lapop12 = readRDS('data/lapop12.rds')

#### Ideology HetFX #### 
m = lm_robust(soc.cl_bin ~ trial*ideolgyr + trend + q1 + q2 + weekend, 
              fixed_effects = estratopri + tamano, 
              se_type = 'stata',
              data = lapop12)
look = cbind.data.frame(m$coefficients, m$conf.low, m$conf.high)
look$var = substring(row.names(look), 15)
look = look[15:23,]
colnames(look)[1:4] = c('coef', 'low', 'high', 'var')
look$var = as.numeric(look$var)

social_hetfx = ggplot(look, aes(var, coef)) + 
  geom_point() + 
  geom_ribbon(aes(x = var, ymin = low, ymax = high), alpha = .2) + 
  geom_hline(yintercept = 0, col = 'red', lty = 2) + 
  xlab('Trial x Ideology (5 is Reference)') + 
  ylab('Estimate') + 
  ggtitle('Reject Social Cleansing') +
  theme_minimal()


m = lm_robust(torture_bin ~ trial*ideolgyr + trend + q1 + q2 + weekend, 
              fixed_effects = estratopri + tamano, 
              se_type = 'stata',
              data = lapop12)
look = cbind.data.frame(m$coefficients, m$conf.low, m$conf.high)
look$var = substring(row.names(look), 15)
look = look[15:23,]
colnames(look)[1:4] = c('coef', 'low', 'high', 'var')
look$var = as.numeric(look$var)

torture_hetfx = ggplot(look, aes(var, coef)) + 
  geom_point() + 
  geom_ribbon(aes(x = var, ymin = low, ymax = high), alpha = .2) + 
  geom_hline(yintercept = 0, col = 'red', lty = 2) + 
  xlab('Trial x Ideology (5 is Reference)') + 
  ylab('Estimate') + 
  ggtitle('Reject Torture') +
  theme_minimal()

m = lm_robust(fair_trial ~ trial*ideolgyr + trend + q1 + q2 + weekend, 
              fixed_effects = estratopri + tamano, 
              se_type = 'stata',
              data = lapop12)
look = cbind.data.frame(m$coefficients, m$conf.low, m$conf.high)
look$var = substring(row.names(look), 15)
look = look[15:23,]
colnames(look)[1:4] = c('coef', 'low', 'high', 'var')
look$var = as.numeric(look$var)

fair_trial_hetfx = ggplot(look, aes(var, coef)) + 
  geom_point() + 
  geom_ribbon(aes(x = var, ymin = low, ymax = high), alpha = .2) + 
  geom_hline(yintercept = 0, col = 'red', lty = 2) + 
  xlab('Trial x Ideology (5 is Reference)') + 
  ylab('Estimate') + 
  ggtitle('Fair Trials') +
  theme_minimal()

het_fx_plot = cowplot::plot_grid(social_hetfx, torture_hetfx, fair_trial_hetfx, 
                                 labels = 'AUTO')
ggsave('fig-out/het_fx_plot.pdf')
